﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GWApplication;


namespace GWPresentation
{

    /// <summary>
    /// 这里并没有应用mvvm，只是根据自己的理解做了一些工作
    /// </summary>
    public class AppViewModel
    {


        protected AppViewModel()
        {

            _tvProject = new ProjectViewModel();
 
        }



        static AppViewModel current;

        public static AppViewModel Current
        {
            get {

                if (current==null)
                {
                    current = new AppViewModel();
                    
                }

                return AppViewModel.current; 
            
            }
           
        }



        public void Init()
        {
            ProjectService.CurrentService.ProjChanged += new FXnaInfrastructure.ProjHandler(CurrentService_ProjChanged);
        }



        protected void ResetViewModel()
        {


            this._tvProject.Refresh();
            


        }



        void CurrentService_ProjChanged(FXnaInfrastructure.ProjChangedType chType)
        {

            switch (chType)
            {
                case FXnaInfrastructure.ProjChangedType.NEW:
                    this.ResetViewModel();
                    break;
                case FXnaInfrastructure.ProjChangedType.SAVE:
                    break;
                case FXnaInfrastructure.ProjChangedType.CLOSE:
                    this.ResetViewModel();
                    break;
                case FXnaInfrastructure.ProjChangedType.OPEN:

                    this.ResetViewModel();
                    break;
                default:
                    break;
            }
           
        }



        ProjectViewModel _tvProject;

        public ProjectViewModel TvProject
        {
            get { return _tvProject; }
            set { _tvProject = value; }
        }




        /// <summary>
        /// 主要用于界面enable 的绑定
        /// </summary>
        public bool IsProjectEnabled
        {

            get {

                return !ProjectService.CurrentService.BNullProj;
            }

            
        }





    }
}
